//
//  SectionsViewController.m
//  Sections
//
//  Created by Haili Ma on 11/18/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "SectionsViewController.h"

@implementation SectionsViewController

@synthesize names;
@synthesize keys;


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



#pragma mark -
#pragma mark UIViewController Methods

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"];
	NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
	self.names = dict;
	[dict release];
	
	NSArray *array = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
	self.keys = array;
	//  [super viewDidLoad];
}



/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[names release];
	[keys release];
    [super dealloc];
}

#pragma mark -
#pragma mark Table View Data Source Methods

- (NSInteger) numberOfSelectionsInTableView: (UITableView *)tableView {
	return [keys	count];
}

- (NSInteger) tableView: (UITableView *)tableView numberOfRowsInSelection:(NSInteger) section {
	NSString *key = [keys objectAtIndex:section];
	NSArray *namesSection = [names objectForKey:key];
	return [namesSection count];
}
@end
